<template>
  <div class="HuikuiInfoKeYun el-card is-always-shadow el-card__body">
    <el-dialog
      title="回馈预览"
      :visible.sync="dialogVisible"
      @close="closed"
      width="950px">
      <avue-crud
        ref="crudTwo"
        :option="optionTableOne"
        :data="listTableOne">
        <template slot="menuLeft">
          TVM单台设备票款差异信息回馈
        </template>
      </avue-crud><br/><br/><br/>
      <avue-form :disabled="isReload" :option="option" v-model="formData" @submit="handleSubmit">
        <template  slot="kyReplyReason" slot-scope="scope">
          <el-select :disabled="showType==2" v-model="kyReplyReason" placeholder="请选择" style="width: 150px">
            <el-option
              v-for="(item,index) in kyReplyReasonList"
              :key="index"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
	<template  slot="replyReason" slot-scope="scope">
          <el-select :disabled="true" v-model="replyReason" placeholder="请选择" style="width: 150px">
            <el-option
              v-for="(item,index) in replyReasonList"
              :key="index"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="menuForm" >
          <el-button v-if="showType==1" type="primary" @click="handleSubmit" >保存</el-button>
          <el-button @click="closed" >返回</el-button>
        </template>
      </avue-form>
    </el-dialog>
  </div>
</template>


<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import {fenExYuangettoFixed,getSysDictItemListToDict,getQianxiangType,getLineName,getStationName} from "../../../../../../api/subwayRat/commonCheck";
  import {updateSwAuTvmSingleAssistKY} from "../../../../../../api/stationTiecketManager/shuJuXieChaGuanLi/TVM/XT/DTSB/TVMDanTaiSheBeiCYKeYun";
  export default {
    components:{
    },
    data() {
      return {
        kyReplyReason :'',
	replyReason :'',
        optionTableOne:{},
        listTableOne:[],
        option:{},
        showType : 0,
        isReload:true,
        dialogVisible:true,
        formData:{},
        kyReplyReasonList:[],
	replyReasonList:[]
      }
    },
    created() {
      this.getOption();
      getSysDictItemListToDict({"type":"KY_REPLY_REASON"}).then((response)=>{
        this.kyReplyReasonList = response.data.data;
      });
      getSysDictItemListToDict({"type":"JD_REPLY_REASON"}).then((response)=>{
        this.replyReasonList = response.data.data;
      });
    },
    methods: {
      async handleSubmit(){
        if(''==this.kyReplyReason){
          this.$message.warning("请选择回馈原因后提交！");
          return
        }
        let p = {
          id:this.formData.id,
          kyReplyReason:this.kyReplyReason,
          kyReplyDetail:this.formData.kyReplyDetail
        };
        await updateSwAuTvmSingleAssistKY(p).then((response)=>{
        });
        this.$message.success("提交成功");
        this.$parent.getList();
        this.closed();
      },
      recallShow(row){
        Object.assign(this.formData,row);
        this.listTableOne.push(row);
        this.kyReplyReason = row.kyReplyReason;
	this.replyReason = row.replyReason;
        if(2==this.showType){
          this.option.group[0].column[1].disabled = true;
        }
      },
      closed(){
        this.dialogVisible=false;
        this.$parent.isShowDia=false;
      },
      getOption(){
        this.showType = this.$parent.showType;
        if(1 == this.$parent.showType) {
          this.isReload = false;
        }
        this.optionTableOne = {
          border: false,
          index: false,
          indexLabel: '序号',
          stripe: false,
          menuAlign: 'center',
          menu: false,
          viewBtn: false,
          editBtn: false,
          emptyBtn:false,
          delBtn: false,
          align: 'center',
          addBtn: false,
          column: [{
            fixed: true,
            label: '主键',
            prop: 'id',
            span: 24,
            type: 'input',
            hide: true
          }, {
            hide: false,
            label: '线路',
            prop: 'lineCode',
            type: 'select',
            filterable : true,
            search: false,
            formatter: function(row, value , label, column){
              return getLineName(value);
            },
            display: true // 动态显隐控制不能删除
          }, {
            hide: false,
            label: '站点',
            prop: 'stationCode',
            type: 'select',
            filterable : true,
            search: false,formatter: function(row, value , label, column){
              return getStationName(row.lineCode,value);
            },
            display: true// 动态显隐控制不能删除
          },
          {
            hide: false,
            label: 'TVM编号',
            prop: 'tvmCode',
            type: 'select',
            search: false,
            filterable : true,
            dicFlag: false,
            props: {
              label: 'tvmCode',
              value: 'tvmCode'
            },
            dicUrl: "/check/check/getSwPmTvmCodeList?stationCode={{key}}"
          }, {
            label: '收入日期',
            prop: 'incomeTime',
            type: 'datetime',
            format: 'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            width: 120,
          }, {
            label: 'SC售票',
            prop: "saleAmount",
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'saleAmount');
            },
            hide: true
          },  {
            label: 'SC充值',
            prop: "depositAmount",
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'depositAmount');
            },
            hide: true
          },  {
            width:120,
            label: 'SC故障退款',
            prop: "errorRefundAmount",
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'errorRefundAmount');
            },
            hide: true
          },  {
            width:120,
            label: '系统金额',
            prop: "tvmBillOrderMoney",
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'tvmBillOrderMoney');
            }
          }, {
            label: '实点金额',
            prop: "actualMoney",
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'actualMoney');
            }
          }, {
            width:120,
            label: '差异金额',
            prop: 'diffMoney',
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'diffMoney');
            }
          }, {
            width:120,
            label: '协查售卖金额',
            prop: 'replySaleMoney',
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'replySaleMoney');
            }
          }, 
          {
            width:120,
            label: '协查充值金额',
            prop: 'replyRechargeMoney',
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'replyRechargeMoney');
            }
          }, {
            width:160,
            label: '协查故障退款金额',
            prop: 'replyErrorReturnMoney',
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'replyErrorReturnMoney');
            }
          }, {
            label: '合计',
            prop: 'replyErrorTotal',
            formatter:function (row,value , label, column) {
              const replyRechargeMoney = row.replyRechargeMoney;
              const replySaleMoney = row.replySaleMoney;
              const replyErrorReturnMoney = row.replyErrorReturnMoney;
              let sum = 0;
              if (!isNaN(replyRechargeMoney)) {
                sum += replyRechargeMoney;
              }
              if (!isNaN(replySaleMoney)) {
                sum += replySaleMoney;
              }
              if (!isNaN(replyErrorReturnMoney)) {
                sum += replyErrorReturnMoney;
              }
              row.replyErrorTotal = sum;
              return fenExYuangettoFixed(row,'replyErrorTotal');
            }
          }]
        };

        this.option={
          submitBtn:false,
          emptyBtn:false,
          group:[{
              icon:'',
              label: '',
              // collapse:false,
              prop: 'group',
              column: [{
                label: '机电专业回馈差异原因',
                prop: 'replyReason',
                formslot : true,
                labelWidth:130,
		disabled:true
              },{
                label: '机电专业差异详情',
                prop: 'replyContent',
                type:'textarea',
                labelWidth:130,
                disabled:true
              },{
                label: '客运专业回馈差异原因',
                prop: 'kyReplyReason',
                formslot : true,
                labelWidth:130
              },{
                label: '客运专业差异详情',
                prop: 'kyReplyDetail',
                type:'textarea',
                labelWidth:130,
                disabled:this.showType==2
              }]
            }]
        }
      }
    },
    mounted() {
    }
  }
</script>
